package com.lambda.lambda.stream;

import com.lambda.lambda.lambda.Student;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class StreamPractise {

    @Before
    public void before(){
        Trader raoul=new Trader("raoul","cambridge");
        Trader mario=new Trader("mario","milan");
        Trader alan=new Trader("alan","cambridge");
        Trader brian=new Trader("brian","cambridge");

        List<Transaction> transactions = Arrays.asList(new Transaction(raoul, 2011, 300),
                new Transaction(mario, 2012, 300),
                new Transaction(alan, 2011, 300),
                new Transaction(brian, 2012, 300),
                new Transaction(raoul, 2012, 300),
                new Transaction(mario, 2011, 300));


    }

    @Test
    public void test01(){
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        List<Integer> collect = list.stream().map(x -> x * x).collect(Collectors.toList());
        System.out.println(collect);
    }

    List<Student> students= Arrays.asList(
            new Student("张三",20,99),
            new Student("李四",10,100),
            new Student("王五",30,100),
            new Student("赵六",30,120)
    );
    @Test
    public void test02(){
        Optional<Integer> reduce = students.stream().map(x->1).reduce(Integer::sum);
        System.out.println(reduce.get());
    }
}
